﻿class Ball {
	private var __instance:MovieClip;
	private var __size:Number;
	private var __x0:Number;
	private var __y0:Number;
	private var __vx:Number;
	private var __vy:Number;
	private var __isDraging:Boolean;
	function Ball(instance_mc:MovieClip, size:Number, x0:Number, y0:Number) {
		__instance = instance_mc;
		__size = size;
		__x0 = x0;
		__y0 = y0;
		__vx = 0;
		__vy = 0;
		__isDraging = false;
		init();
	}
	private function init():Void {
		__instance.lineStyle(0, 0x000000, 100);
		__instance.beginFill(Math.random()*0xffffff, 100);
		__instance.moveTo(-__size/2, -__size/2);
		__instance.lineTo(__size/2, -__size/2);
		__instance.lineTo(__size/2, __size/2);
		__instance.lineTo(-__size/2, __size/2);
		__instance.lineTo(-__size/2, -__size/2);
		__instance.endFill();
		__instance.onPress = mx.utils.Delegate.create(this, instanceOnPress);
	}
	public function get x0():Number {
		return __x0;
	}
	public function get y0():Number {
		return __y0;
	}
	public function get size():Number {
		return __size;
	}
	public function get x():Number {
		return __instance._x;
	}
	public function set x(n:Number):Void {
		if (!__isDraging) {
			__instance._x = n;
		}
	}
	public function get y():Number {
		return __instance._y;
	}
	public function set y(n:Number):Void {
		if (!__isDraging) {
			__instance._y = n;
		}
	}
	public function get vx():Number {
		return __vx;
	}
	public function set vx(n:Number):Void {
		__vx = n;
	}
	public function get vy():Number {
		return __vy;
	}
	public function set vy(n:Number):Void {
		__vy = n;
	}
	private function instanceOnPress():Void {
		__isDraging = true;
		__instance.startDrag(false);
		__instance.onRelease = mx.utils.Delegate.create(this, instanceOnRelease);
	}
	private function instanceOnRelease():Void {
		__instance.stopDrag();
		__instance.onRelease = null;
		__isDraging = false;
	}
}
